<template>

  <div>
    <el-form ref="form"  label-width="80px" inline>
      <el-form-item label="项目名称">
        <el-input v-model="queryParam.name" placeholder="请输项目名称" ></el-input>
      </el-form-item>
      <el-form-item label="服务人">
        <el-input v-model="queryParam.personnel" placeholder="请输服务人" ></el-input>
      </el-form-item>
      <el-form-item  >
        <el-button type="primary" size="mini" @click="search()">搜索</el-button>
      </el-form-item>
    </el-form>


    <el-button type="primary" @click="dialogFormVisible=true" >添加</el-button>



    <el-table :data="tableData" size="mini" style="width: 100%" v-loading="loading">
      <el-table-column align="center" type="index" label="序号" width="60">
      </el-table-column>
<!--      <el-table-column prop="roomsId" label="房间id" align="center" width="180"></el-table-column>-->
      <el-table-column prop="name" label="项目名称" align="center"></el-table-column>
      <el-table-column prop="price" label="价格" align="center"></el-table-column>
      <el-table-column prop="description" label="描述" align="center"></el-table-column>
      <el-table-column prop="personnel" label="服务人" align="center"></el-table-column>
      <el-table-column prop="levelId" label="级别" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">

          <el-button type="primary" size="mini" @click="toEdit(scope.row.contentId)">修改</el-button>
          <el-button type="warning" size="mini" @click="deleteById(scope.row.contentId)">删除</el-button>
        </template>

      </el-table-column>

    </el-table>

    <div class="block">
      <span class="demonstration"></span>
      <el-pagination
          @size-change="queryList"
          @current-change="queryList"
          :current-page.sync="queryParam.current"
          :page-size.sync="queryParam.size"
          :page-sizes="[5,10,15,20,50]"
          layout="total,sizes, prev, pager, next"
          :total="total">
      </el-pagination>
    </div>

    <el-dialog title="添加护理内容" :visible.sync="dialogFormVisible" v-if="dialogFormVisible">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="项目名称">
          <el-input v-model="form.name" ></el-input>
        </el-form-item>
        <el-form-item label="价格">
          <el-input v-model="form.price"></el-input>
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="form.description"></el-input>
        </el-form-item>
        <el-form-item label="服务人">
          <el-input v-model="form.personnel"></el-input>
        </el-form-item>
        <el-form-item label="级别">

          <el-select v-model="form.levelId" placeholder="请选择">
            <el-option
                v-for="item in levelObjs"
                :key="item.levelId"
                :label="item.levelName"
                :value="item.levelId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="save()">保存</el-button>
        </el-form-item>

      </el-form>
    </el-dialog>

  </div>


</template>

<script>


// import axios from "axios";
// axios.defaults.baseURL = "http://localhost:8080";
import service from "@/utils/request.js";
import request from "@/utils/request.js";

export default {
  name: 'Dept',

  data() {
    return {
      dialogFormVisible: false,
      tableData: [],
      loading: false,
      form:{
        contentId:'',
        name:'',
        price:'',
        description:'',
        personnel:'',
        levelId:'',
      //  1111


      },
      levelObjs:[],
      total:0,
      pages:0,
      queryParam:{
        current:1,
        size:5,
        name:'',
        personnel:''
      }
    }
  },
  methods: {
    //关联字段查询
    findLeve(){
      request.get("/nurseLevel/list").then(res =>{
        // eslint-disable-next-line no-empty
        console.log("res ",res)

        this.levelObjs = res

      })

    },



    search(){
      this.queryParam.current=1;
      this.queryList();
    },


    queryList() {
      this.loading = true;
      service.get("/nurseContent/page",{params:this.queryParam}).then((res) => {
        this.tableData = res.records;
        this.total = res.total;
        console.log("tableData:" ,this.tableData)
        console.log("total:" ,this.total)
        this.pages = res.pages;
        this.loading = false
      })
    },
    toEdit(id){
      service.get("/nurseContent/getById/"+id).then((res) => {
        this.form = res;
        this.dialogFormVisible = true;
      })
    },
    deleteById(id){
      this.$confirm('是否删除', '确认信息') .then(() => {
        service.get("/nurseContent/removeById/"+id).then((res) => {
          const success = res
          if(success){
            this.$message.success("删除成功");
            this.queryList();
          }
        })
      });




    },
    save(){
      service.post("/nurseContent/saveOrUpdate",this.form  ).then((res) => {
        const success = res
        if(success){
          this.$message.success("保存成功");
          this.dialogFormVisible = false;
          this.queryList();
        }
      })
    }
  },
  created() {
    this.queryList();
    this.findLeve();

  }

}
</script>

<style scoped>


</style>